<?php
header('content-type:text/html;charset=utf-8');
echo '<h2>接收到新用户注册！</h2>';
echo '<p>用户名:'.$_POST['username'].'</p>';
echo '<p>密码：'.$_POST['password'].'</p>';
echo '<p>邮箱：'.$_POST['email'].'</p>';
echo '<p>IP地址：'.$_SERVER['REMOTE_ADDR'].'</p>';
echo '<p>浏览器环境：'.$_SERVER['HTTP_USER_AGENT'].'</p>';
echo '<p>请求来源：'.$_SERVER['HTTP_REFERER'].'</p>';

$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];

$link=mysqli_connect('localhost','root','') or die('数据库连接失败！');
mysqli_query($link,'set names utf8');
mysqli_query($link,'use itcast') or die('itcast数据库不存在！');

//防止SQL注入
$username=mysqli_real_escape_string($link,$username);
$email=mysqli_real_escape_string($link,$email);

//判断用户名是否已经存在
$sql="select `id` from `user` where `username`='$username'";
$rst=mysqli_query($link,$sql);
if (mysqli_fetch_row($rst)){
    die('用户名已经存在，请换个用户名。');
}

//使用MD5增强密码安全性
$password=md5($password);
$sql="insert into `user`(`username`,`password`,`email`) values('$username','$password','$email')";
$rst=mysqli_query($link,$sql);
?>
